<template>
	<view class="viewport">
		<div class="profile">
			<view class="block">
				<view>{{UserInfo.name}}</view>
				<navigator url="/pagesMember/settings/index" hover-class="none"><text class="icon icon-shezhi"></text>设置
				</navigator>
			</view>
		</div>
		<view class="menu">
			<navigator url="/pagesMember/message/index" hover-class="none">
				<view class="menu-item">
					<view class="name"><text class="icon icon-youhuijuan1"></text>优惠和消息</view>
					<text class="icon icon-jiantou2"></text>
				</view>
			</navigator>
			<navigator url="/pagesMember/aboutUs/index" hover-class="none">
				<view class="menu-item">
					<view class="name"><text class="icon icon-guanyu"></text>关于我们</view>
					<text class="icon icon-jiantou2"></text>
				</view>

			</navigator>
		</view>
		<button style="margin:100rpx 32rpx;background-color: #fff;color:#666" @click="logout()">
			退出登陆
		</button>



	</view>
</template>

<script setup lang="ts">
	import { getProfileSummary, postLogout } from '@/api/User'
	import type { UserProfile } from '@/types/index'
	import { ref } from 'vue'
	import { onShow } from '@dcloudio/uni-app';
	import { useMemberStore } from '../../store';
	const store = useMemberStore()
	const UserInfo = ref<UserProfile>(null)
	const loading = ref(false)
	onShow(() => {
		loading.value = true
		initData()
		loading.value = false
	})
	const initData = async () => {
		const res = await getProfileSummary()
		console.log(res)
		UserInfo.value = res.data
		store.setProfileSummary(res.data)
	}
	const logout = () => {
		uni.showModal({
			title: '确认退出登录',
			content: '您确定要退出当前账号吗？',
			success: async (res) => {
				if (res.confirm) {
					// await postLogout()
					store.clearProfileSummary()
					uni.clearStorageSync()
					uni.navigateTo({
						url: '/pages/login/index'
					})

				}
			},
		})
	}
</script>

<style lang="scss">
	page {
		height: 100%;
		overflow: hidden;
		background-color: #f7f7f8;
	}

	.viewport {
		height: 100%
	}

	/* 用户信息 */
	.profile {
		margin: 32rpx;
		background-color: #fff;
		border-radius: 15rpx;
		box-shadow: 0 3px 10px #e1e1e1;
		padding: 32rpx;

		.block {
			background: linear-gradient(to right, #D1D5DB, #E5E7EB);
			display: flex;
			justify-content: space-between;
			padding: 32rpx;
			border-radius: 15rpx;
		}

	}

	.menu {
		margin: 32rpx;
		background-color: #fff;
		border-radius: 15rpx;
		box-shadow: 0 3px 10px #e1e1e1;
		padding: 32rpx;

		.menu-item {
			padding: 32rpx;
			display: flex;
			justify-content: space-between;
			border-bottom: 1px solid #e1e1e1;

			.icon-jiantou2 {
				font-size: 40rpx;
				color: #666
			}

			.name {
				.icon {
					color: $uni-color-primary;
					margin-right: 10rpx;
					background-color: #dbeafe;
					border-radius: 5rpx;
					padding: 5rpx;
				}
			}
		}
	}


	/* 猜你喜欢 */
	.guess {
		background-color: #f7f7f8;
		margin-top: 20rpx;
	}
</style>